home *** CD-ROM | disk | FTP | other *** search
- // Copyright: © 1993 Apple Computer, Inc. All rights reserved.
- // Author: John R. Powers, III (original)
- // Victor J. Hnyp (extensions)
- // Dave Lyons (maintenance)
- // Date: 13-Jan-94
-
- /*
- <3.01> 13-Jan-94 DAL Removed check of process type (signature is enough),
- per Dec 93 code review.
- ----------------------------------------------------------------------------
- 1.0d1e3 17-Sep-92 added type 'dfil' to match with desk accessories (JBM3)
- 1.0d1e2 13-Jul-92 change creator from 'ctxt' to 'reno'
- 1.0d1e1 22-May-92 original creation
- */
-
- #pragma load "AllHeaders.dump"
-
- #include "Utility.h"
- #include "Proto.h"
- #include "Context.h"
- #include "Process.h"
-
- /* ------------------ Forward Declaration ---------------- */
- short IsProcessAvailable(ProcessTestPtr pContextRes);
-
-
- pascal OSErr main(ContextSelectorPtr msg, Size inSize,
- void* outMessage, Size* outSize, Handle /*startGlobals*/)
- {
- Boolean ret = false;
- OSErr err = errAECorruptData;
-
- if(inSize < sizeof(ContextSelector)) /* If inSize is < length of selector (a long), */
- return err; /* return an error. Would be nice to have a specific error # */
-
- switch (msg->selector)
- {
- case isFront:
- case isOpen:
- ret = IsProcessAvailable((ProcessTestPtr) msg);
- err = SetContextResult(&ret, sizeof(Boolean), outMessage, outSize);
- break;
-
- default: /* None of the pre-defined types. Exit with error */
- break; /* Would be nice to have a specific error # */
- }
-
- return err;
- }
-
-
- // ------------------------------------------------------------------------
- // Formerly TPanel::IsApplicationOk (pre-1.0d1e26)
- // Context check for application.
- // Use the Process Manager to determine the state of the application
- // (process) described in pContextRes.
- // Target application signature must be provided.
- // We check for processTypes of 'APPL' and 'FNDR' because
- // frequently our target application is the Finder.
-
- short
- IsProcessAvailable(ProcessTestPtr pContextRes)
- {
- ProcessSerialNumber PSN;
- ProcessInfoRec info;
- OSErr err;
- short result=false;
- Str31 aProcessName;
- FSSpec aProcessAppSpec;
-
- // Process Serial Number must be valid, make it so.
- PSN.highLongOfPSN = 0;
- PSN.lowLongOfPSN = kNoProcess;
-
- // We also have to fill-in (or make NULL) some fields.
- info.processInfoLength = sizeof(ProcessInfoRec);
- info.processName = aProcessName;
- info.processAppSpec = &aProcessAppSpec;
-
- // What are we testing for?
- switch (pContextRes->selector)
- {
- case isFront:
- err = GetFrontProcess(&PSN);
- if(err == noErr)
- {
- err = GetProcessInformation(&PSN, &info);
- if(err == noErr)
- {
- result = (info.processSignature == pContextRes->signature);
- }
- }
- break;
-
- case isOpen:
- // Search for our application (process) as the
- // "current process" in background or foreground.
- while (GetNextProcess(&PSN) == noErr)
- {
- if(GetProcessInformation(&PSN, &info) == noErr)
- {
- if(info.processSignature == pContextRes->signature)
- {
- result = true; // Found it.
- break; // To exit the while…
- }
- }
- }
- break;
- }
-
- return result;
- }
-